#ifndef _PHY_CONSTANTS_H
#define _PHY_CONSTANTS_H (1)
/*
 * PhyConstants.h
 * Created on Feb 23, 2004; 2:58 PM
 * by sriram and Basheer
 */
/*
** Copyright 2004 by Hellosoft Inc. All rights reserved. No part
** of this publication, or any software included with it, may be
** reproduced, stored in a retrieval system, or transmitted in
** any form or by any other means, including photocopying,
** electronic or mechanical recording or otherwise, without
** prior written permission of the copyright holder
**
** Hellosoft Confidential and Proprietary information
**
**-------------------------------------------------------------
**/

//#define RUN_MAC         0
#define RUN_RX          1
#define RUN_TX          1
#define CMF             0

#define RF_SUBB_ALIGN   7

//#define ABS(X)    (((X) >= 0)? (X): (-X))

#define RX_FS                       (22e6)

/*PHY CONSTANTS */

#define    OUTBUFFSIZE        64
#define    EQOUTBUFFSIZE    64


#define EQUALIZER_SAMPLES_12        11
#define EQUALIZER_SAMPLES_5511        8
#define RX_SAMPLE_SIZE                22
#define RX_DOWNSAMPLE_SIZE            11
#define PREAMBLE_REFSIZE            (3168)
#define PREAMBLE_DOWNSAMPLE_REFSIZE    (1584)

#define PREAMBLE_SYNC_SYMBOLS   8
#define TRAINING_SYMBOLS        32
#define PREAMBLE_NUM_CORR       20
#define CORR_LEN                (RX_DOWNSAMPLE_SIZE*PREAMBLE_SYNC_SYMBOLS)

#define    PREAMBLESYNCSIZE    104 //(11*8 + 16)


/* Energy Detection Variables*/
#define  ED_THRESH_DBM       (-87)

#ifdef FROM_AP
#define  ED_THRESH           (450000)  /*(921403)*/ //450000
#else
#define  ED_THRESH           (900000000)
#endif

#define  PHY_RX_SETTING_INITIAL_AGC_GAIN (79)
#define  RX_SAMP_PER_SYMB          (22)
#define  TX_SAMP_PER_SYMB          (22)
#define  RX_SAMP_PER_CHIP       (2)

#define    ED_SYMBOLS        (1)
#define AGC_SYMBOLS        (1)
#define    BARKER_CORR_SYMBOLS    (2)
#define CARRIER_EST_SYMBOLS    (31)

#define TX_HEADER_INIT_SCRAM_STATE    (0x49)
#define TX_PREAMBLE_INIT_SCRAM_STATE    (0x6c)

/* CMF Constant */

#define  CMF_TAP_LEN              (8)
#define  MAX_PRECURSOR            (CMF_TAP_LEN)
#define  MAX_POSTCURSOR           (CMF_TAP_LEN-1)
#define  CMF_FILTER_FLAG          (0)
#define  SFD_TIME_OUT           (128)
#define  N_BITS_PER_BYTE           (8)
#define  N_HEADER_SYMB             (48)

/*'1' to enable the Circular buffer reading and
  '0' to disable the Circular buffer reading
*/
#define  CIRCULAR_BUFFER     (1)

#define FREE     0
#define BUSY     1

#define  SHORT_SFD_PATTERN_TX    (0x05cf)
#define  SFD_PATTERN_TX         (0xf3a0)
#define  SFD_PATTERN            (0x05cf)
#define  SFD_SHIFT_PATTERN_1BIT (0x02e7)
#define  SFD_SHIFT_PATTERN      (0x0173)
#define  CRC16_PATTERN          (0xf0b8)
#define  CRC32_PATTERN          (0xdebb20e3)
#define  N_BITS_PER_BYTE        (8)
#define  MUL_FAC_8BY11            (47662)  /* 8/11 in u(0,16) format*/
#define  N_BITS_PER_BYTE           (8)

#define PLCP_HEADER_BITS (48)
#define PLCP_CRC16_BITS  (16)
#define PLCP_SFD_BITS    (16)

#define NUM_CRC16_OCTETS (2)
#define NUM_HDR_OCTETS (6)
#define NUM_PAYLOAD_OCTETS (1024)
#define NUM_PAYLOAD_BITS (NUM_PAYLOAD_OCTETS * 8)

#define PLCP_SHORT_PREAMBLE_BITS (56)
#define PLCP_PREAMBLE_BITS (128)
#define DUAL_BUF_FIRST_HALF     (0)
#define DUAL_BUF_QUARTER_SIZE   (24)

#define TX_PLCP_INIT  (0)
#define TX_PLCP_PREAMBLE (1)
#define TX_PLCP_HEADER (2)
#define TX_PLCP_PAYLOAD (3)
#define TX_IDLE_STATE (4)

// TODO merge with MAC data rates
#define ONE_MBPS (0x0A)
#define TWO_MBPS (0x14)
#define FIVEDOTFIVE_MBPS (0x37)
#define ELEVEN_MBPS (0x6E)

#define LONGPREAMBLE (1)
#define SHORTPREAMBLE (2)

/* PLCP Header Field Constants */
#define  PLCP_SIGNAL_OFF (0)
#define  PLCP_SERVICE_OFF (1)
#define  PLCP_LENGTH_OFF (2)

/* PLCP Header-Service Field Constants */
#define  CCK_CLK_LOCK (0x04)
#define  PBCC_CLK_LOCK (0x0C)
#define  CCK_CLK_NOLOCK (0x00)
#define  PBCC_CLK_NOLOCK (0x08)


enum {
  HS_COMPLETE,
  HS_INCOMPLETE,
  HS_ERROR,
  HS_HEAD_CRC_ERROR,
  HS_RATE_ERROR,
  HS_SFD_TIMEOUT,
  HS_TX_INTERRUPT,
  HS_ED_TIMOUT
};

enum {
  HS_SUCCESS,
  HS_FAILURE
};

enum {
  HS_ON,
  HS_OFF
};

#endif

